var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var do_App = sm("do_App");
// 实例化一个BaiduLocation对象
var dingwei = sm("do_BaiduLocation");
var qqHttp = require("helper/http");
var bdmapHelper = require("helper/bdmap");
var communityUrl = require("url/community");
var httpUrl=communityUrl.url.base.distanceList;

// UI
var map = ui("do_BaiduMapView_1");
var headerAout = ui("headerAout");
// 变量
var mark1 = "";
var iconUrl = "source://image/people.png";
var dingweiX, dingweiY;
var showCMarkers="showCMarkers";
// 加载头部
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
// andriod返回键
do_Page.on("back", function() {
	do_App.closePage();
});
// 左上角-返回
var headerLeft = ui(addheader + ".headerLeft");
// 右上角-
var headerRight = ui(addheader + ".headerRight");
headerRight.visible = false;
headerLeft.on("touch", function() {
	do_App.closePage()
});
var header = ui("header");

header.bindData(hashdata);
hashdata.addData({
	"labelTitle" : "地图",
})
header.refreshData();

// 页面装载完成后，开始初始化工作
do_Page.on("loaded", function() {
	// 读取当前页面的传入参数
	var data = do_Page.getData();
	iconUrl = data.iconUrl;
	dingweiX=bdmapHelper.getDingwei().longitude;
	dingweiY=bdmapHelper.getDingwei().latitude;
	map.setCenter({
		latitude : dingweiY,
		longitude : dingweiX
	});
	mark1 = [ {
		"id" : showCMarkers+"1",
		"latitude" : dingweiY,
		"longitude" : dingweiX,
		"url" : "source://image/people.png",
		"info" : "我"
	} ];
	map.addMarkers({
		data : mark1
	});
	loadMarker();
});
function loadMarker() {
	var param = {
		x : dingweiX,
		y : dingweiY
	}
	qqHttp.post(httpUrl, param, function(data) {
		if (data.list.length > 0) {
			defaultY = data.list[0].y;
			defaultX = data.list[0].x;
			for (var i = 0; i < data.list.length; i++) {
				var id = i + 2;
				var x = data.list[i].x;
				var y = data.list[i].y;
				var info = data.list[i].name;
				var mark2 = [ {
					"id" : showCMarkers + id,
					"latitude" : y,
					"longitude" : x,
					"url" : iconUrl,
					"info" : info
				} ];
				map.addMarkers({
					data : mark2
				})
			}
		}
	})
}
